package br.com.spam.pipeline.iu;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class IU_Processor extends JPanel
{
	private static final long serialVersionUID = -1665371433537188473L;

	private IU_Datashow parent;

	private JLabel title = new JLabel("Processador", (int) CENTER_ALIGNMENT);

	private JLabel currentClock = new JLabel("Clock Corrente:");
	private JTextField vCurrentClock = new JTextField();

	private JLabel PC = new JLabel("PC:");
	private JTextField vPC = new JTextField();

	private JLabel completedInstructions = new JLabel("Instruções concluídas:");
	private JTextField vCompletedInstructions = new JTextField();

	private JLabel produtivity = new JLabel("Produtividade:");
	private JTextField vProdutivity = new JTextField();

	public IU_Processor(IU_Datashow parent)
	{
		this.parent = parent;

		this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		this.setLayout(new BorderLayout());
		this.add(this.title, BorderLayout.NORTH);
		this.title.setBorder(BorderFactory.createLineBorder(Color.BLACK));

		JPanel aux = new JPanel();
		aux.setLayout(new GridLayout(0, 2));
		this.add(aux, BorderLayout.CENTER);

		aux.add(this.currentClock);
		aux.add(this.vCurrentClock);
		this.vCurrentClock.setEditable(false);
		this.currentClock.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		this.vCurrentClock.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		this.currentClock.setBackground(Color.WHITE);
		this.currentClock.setOpaque(true);
		this.vCurrentClock.setBackground(Color.WHITE);

		aux.add(this.PC);
		aux.add(this.vPC);
		this.vPC.setEditable(false);
		this.PC.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		this.vPC.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		this.PC.setBackground(Color.WHITE);
		this.PC.setOpaque(true);
		this.vPC.setBackground(Color.WHITE);

		aux.add(this.completedInstructions);
		aux.add(this.vCompletedInstructions);
		this.vCompletedInstructions.setEditable(false);
		this.completedInstructions.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		this.vCompletedInstructions.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		this.completedInstructions.setBackground(Color.WHITE);
		this.completedInstructions.setOpaque(true);
		this.vCompletedInstructions.setBackground(Color.WHITE);

		aux.add(this.produtivity);
		aux.add(this.vProdutivity);
		this.vProdutivity.setEditable(false);
		this.produtivity.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		this.vProdutivity.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		this.produtivity.setBackground(Color.WHITE);
		this.produtivity.setOpaque(true);
		this.vProdutivity.setBackground(Color.WHITE);

		this.update();
	}
	public void update()
	{
		if (this.parent.pipeline() != null)
		{
			this.vCurrentClock.setText(String.valueOf(this.parent.pipeline().getCurrentClock()));
			this.vPC.setText(String.valueOf(this.parent.pipeline().getProcessor().getPC()
					.getPersistedValue()));
			this.vCompletedInstructions.setText(String.valueOf(this.parent.pipeline()
					.getCompletedInstructions()));
			this.vProdutivity.setText(String.valueOf(this.parent.pipeline().getProdutivity()));
		}
	}
}
